package com.pp.tourism.web.controller;

import com.pp.tourism.web.dto.ApiResponse;
import com.pp.tourism.web.pojo.ScenicSpot;
import com.pp.tourism.web.pojo.status.ScenicStatus;
import com.pp.tourism.web.service.ScenicSpotService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(tags = "/admin", description = "后台景点管理接口")
@RestController
@RequestMapping("/admin")
public class AdminController {

    @Autowired
    private ScenicSpotService scenicSpotService;

    @ApiOperation("获取全部景点信息接口")
    @PostMapping("/getScenics")
    public ApiResponse<List<ScenicSpot>> getAllScenic() {
        List<ScenicSpot> result = scenicSpotService.queryAllScenics();
        return ApiResponse.ok(result);
    }
    @ApiOperation("获取指定景点id的信息")
    @PostMapping("/getScenicsById")
    public ApiResponse<ScenicSpot> getScenicsById(String id) {
        ScenicSpot result = scenicSpotService.selectById(id);
        return ApiResponse.ok(result);
    }

    @ApiOperation("更新景点价格和景点状态")
    @PostMapping("/update/status")
    public ApiResponse updateScenicStatus(
                                          @ApiParam("景点ID")
                                          @RequestParam(value = "scenicId") Integer scenicId,
                                          @ApiParam("景点状态：OPEN(营业中)、CLOSED(休息中)、MAINTAINANCE(维护中)")
                                          @RequestParam(value = "scenicStatus") ScenicStatus scenicStatus,
                                          @ApiParam("景点价格")
                                          @RequestParam(value = "scenicPrice") Double scenicPrice
                                        ) {
            Assert.notNull(scenicId,"scenicId null");
            scenicSpotService.updateScenicsStatus(scenicId, scenicStatus, scenicPrice);
            return ApiResponse.ok("ok");
    }

}
